import router from './index'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import store from 'store'

//设置路由白名单【不需要登录信息即可打开的页面】
const whiteList = ['/login']

router.beforeEach((to,from,next)=>{
  document.title = "菜谱后台管理-" + to.meta.title;
  NProgress.start();
  //1.判断是否要跳转到白名单的地址中
  if(whiteList.includes(to.path)){
    next();
    return;
  }
  //2.判断当前有没有token
  if(store.getters['admin/getToken']){
    next();
    return;
  }
  next('/login');
})

router.afterEach(()=>{
  NProgress.done();
})